package chen.web.test;

import java.util.Date;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import chen.web.widget.vote.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/test.xml"})
public class VoteManagerTesting {
	
	@Autowired
	private VoteManager vm;

	private Vote createVote(){
		Vote vote = new Vote();
		String title = "fdasfasdfasdf";
		vote.setTitle(title);
		vote.setDateline(new Date());
		vote.setDeadline(new Date(System.currentTimeMillis() + 1000000));
		vote.setOptionalQuantity(1);
		vote.setPublicVoters(true);
		vote.setOptionsContent("abc","ac", "b");
		return vote;
	}
	
	@Test
	public void add_get_update_delete(){
		Vote vote = createVote();
		vote = vm.add(vote);
		Assert.assertTrue(vote.getId() > 0);
		Assert.assertNotNull(vm.get(vote.getId()));
		Assert.assertEquals(vm.get(vote.getId()).getTitle(), vote.getTitle());
		vote.setTitle("hello");
		vm.update(vote);
		Assert.assertEquals(vm.get(vote.getId()).getTitle(), vote.getTitle());
		vm.delete(vote);
		Assert.assertNull(vm.get(vote.getId()));
	}
	
	public void get(){
		
	}
	
	public void vote(){

	}
	
}
